<?php

  namespace app\index\controller;
  use app\index\Controller;
  use think\Db;
  use think\Validate;
  /**
   * @title 申诉（模块12）
   * @description 接口说明
   * @group 申诉
   * @header name:model_id   default:05 desc:模块id
   * @groupremark 已使用错误码：1120001 1120002
   */

   class Appeal extends Controller{

     /**
      * @title 提交申诉
      * @description 接口说明
      * @author 李锐志
      * @url /index/appeal/index
      * @param name:token type:string require:1  other: desc:token
      * @param name:user_id type:int require:1  other: desc:user_id
      * @param name:reason type:int require:1  other: desc:申诉内容
      * @method ~
      * @return error_id: 1120001 校验错误
      * @return error_id: 1120002 提交失败
      */
     public function index(){

       $data = input();
       //验证规则
       $validate = new Validate([
         ['token','require','缺少token'],
         ['user_id','require','未指定用户'],
         ['reason','require','申诉内容不能为空']
       ]);

         //验证数据
       if(!$validate->check($data)){
         $msg['error_id']="1120001";
         $msg['message']=$validate->getError();
         return $this->error($msg);
       }

       $data['create_time'] = time();
       $result = Db::name('driver_degrade_appeal')->strict(false) -> insert($data);
       if($result==true){
         $msg['message'] = '提交成功';
         return $this->success($msg);
       }else{
         $msg['message'] = '提交失败';
         $msg['error_id'] = '1120002';
         return $this->error($msg);
       }
     }
   }
